$import("com.joypard.workflow.definition.DefinitionView");
$import("com.joypard.workflow.definition.DefinitionDI");

/**
 * 流程定义控制器
 */
K.defCtrl("com.joypard.workflow.definition.DefinitionCtrl", {
	view : null,
	initialize : function() {
		this.view = DefinitionView.instance();

		E.addEvents("delDefinitionSuccessEvent");

		E.addListener("delDefinitionEvent", this.onDelDefinition, this);
		E.addListener("startProcessEvent", this.onStartProcess, this);
	},

	onDelDefinition : function(records) {
		var me = this, input = K.input({
			params : {
				definitions : K.arrayToStr(records, function(r) {
					return r.get("deploymentId")
				}, ", ")
			},
			success : function(text) {
				var output = K.output(text);
				if (output.success = 'true') {
					E.fireEvent("delDefinitionSuccessEvent", output);
				}
			}
		});
		K.service(DefinitionDI.urls.delDefinition, input);
	},

	onStartProcess : function(processDefinitionId) {
		var me = this, input = K.input({
			params : {
				processDefinitionId : processDefinitionId
			},
			success : function(text) {
				alert(text);
			}
		});
		K.service(DefinitionDI.urls.startProcess, input);
	}

});